import { setStorage, getStorage } from '../common/storage.js'

const DIFFICULTY_KEY = 'difficulty'

export const DifficultyState = {
  simplicity: 0,
  medium: 1,
  difficulty: 2
}

export const DifficultyName = {
  simplicity: '简单',
  medium: '中等',
  difficulty: '困难'
}



/**
 * 获取难度
 */
export const getDifficulty = () => {
  return getStorage(DIFFICULTY_KEY) || 0
}

/**
 * 设置难度
 * @param {DifficultyState} level 
 */
export const setDifficulty = (level) => {
  setStorage(DIFFICULTY_KEY, level)
}

/**
 * 
 * @returns 
 */
 export const getDifficultyName = () => {
  const diff =  getDifficulty()
  return {
    [DifficultyState.simplicity]: DifficultyName.simplicity,
    [DifficultyState.medium]: DifficultyName.medium,
    [DifficultyState.difficulty]: DifficultyName.difficulty
  }[diff]
}